const { ParameterException } = require('./http-exception');

class Validators {
    static isNull(val, msg = '某个') {
        if(val === undefined || val === null || val == '') {
            throw new ParameterException(`缺少${msg}值`)
        }
        return Validators;
    }

    static isString(val, msg = '某个') {
        if(typeof val === 'string') {
            throw new ParameterException(`${msg}必须为字符串`)
        }
        return Validators;
    }

    static isHave(val, arr, msg = '某个'){
        // console.log('aaa-->',arr.includes[val])
        if(!arr.includes(val)) {
            throw new ParameterException(`${msg}必须为${arr.toString()}之中一个`)
        }
        return Validators;
    }
}

module.exports = Validators